﻿using MyCompany.MyProject.Common;
using MyCompany.MyProject.Serilog.Sink;
using Serilog;
using Serilog.Sinks.PeriodicBatching;

namespace MyCompany.MyProject.Serilog.Configuration;

public static class LogBatchingSinkConfiguration
{
    public static  LoggerConfiguration WriteToLogBatching(this LoggerConfiguration configuration)
    {
        if(!AppSettings.app("AppSettings","LogToDb").ObjToBool())
            return configuration;

        var exampleSink = new LogBatchingSink();

        var batchingOptions = new PeriodicBatchingSinkOptions
        {
            BatchSizeLimit = 500,
            Period = TimeSpan.FromSeconds(1),
            EagerlyEmitFirstEvent = true,
            QueueLimit = 10000
        };

        var batchingSink = new PeriodicBatchingSink(exampleSink, batchingOptions);

        return configuration.WriteTo.Sink(batchingSink);
    }
}
